package com.elloe.数组.有序数组的平方;

import java.util.Arrays;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2022-04-02 19:16
 * To: 真常应物，真常得性，常清常静，常清静矣
 *
 *  双指针
 */
public class SortSquares {
    public static void main(String[] args) {
        int[] nums = {-4,-1,0,3,10};

        int left = 0;
        int right = nums.length - 1;
        int[] result = new int[nums.length];
        int write = nums.length - 1;
        while (left <= right){
            if (nums[left]*nums[left] > nums[right]*nums[right]){
                result[write] = nums[left] * nums[left];
                left++;
            }else{
                result[write] = nums[right] * nums[right];
                right--;
            }
            write--;
        }
        System.out.println(Arrays.toString(result));
    }
}
